<template>
    <div class="physician-list">
        <h2 class="title">{{ $route.meta.title }}<span>护士人员总数：{{ total }}</span></h2>
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="护士姓名" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入护士姓名"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
        <div class="table">
            <el-table
                :data="tableData"
                border
                fit
                style="width: 100%"
                header-cell-class-name="table-header-cell"
                :class="tableData.length === 0 ? 'table-empty' : ''" v-loading="loading" @selection-change="handleSelectionChange"
            >
              <el-table-column
                label="序号"
                type="index"
                width="80">
              </el-table-column>
              <el-table-column label="护士姓名" align="center" prop="name" />
              <el-table-column label="护士性别" align="center" prop="sex">
                <template slot-scope="scope">
                  <span v-if="scope.row.sex === '1'">男</span>
                  <span v-else-if="scope.row.sex === '2'">女</span>
                  <span v-else>{{ scope.row.sex }}</span>
                </template>
              </el-table-column>
              <el-table-column label="护士证号" align="center" prop="nurselicence" />
              <el-table-column label="机构名称" align="center" prop="institutionName" />
              <el-table-column label="学历" align="center" prop="antecedent" />
                <el-table-column label="操作" width="300">
                    <template slot-scope="scope">
                        <div class="operation">
                            <div  @click="handleView(scope)">查看</div>
                            <div  style="margin-left: 20%;" @click="handleEdit(scope)">编辑</div>
                           <!-- <div class="delete" @click="handleDelete(scope.row)">删除</div>-->
                        </div>
                    </template>
                </el-table-column>
            </el-table>
        </div>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
        <el-dialog
            v-if="editDialogVisible"
            title="编辑信息"
            :visible.sync="editDialogVisible"
            width="30%"
            :before-close="handleClose"
            class="edit-dialog"
            top="40vh"
        >
            <div class="edit-box">
                <div class="name">医生姓名<el-input v-model="editData.name"></el-input></div>
                <div class="id-number">身份证号<el-input v-model="editData.idCard"></el-input></div>
                <div class="submit" @click="submitForm">确认修改</div>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import { listNurse, getNurse, delNurse, addNurse, updateNurse, exportNurse } from "@/api/his/nurse";
  // import { listAll, getAll, delAll, addAll, updateAll, exportAll  } from "@/api/his/doctorAll";
export default {
    name: 'PhysicianList',
    data() {
        return {
          // 遮罩层
          loading: true,
          // 导出遮罩层
          exportLoading: false,
          // 选中数组
          ids: [],
          // 非单个禁用
          single: true,
          // 非多个禁用
          multiple: true,
          // 显示搜索条件
          showSearch: true,
          // 总条数
          total: 0,
          // 【请填写功能名称】表格数据
          dockorList: [],
          // 弹出层标题
          title: "",
          // 是否显示弹出层
          open: false,
          // 查询参数
          queryParams: {
            pageNum: 1,
            pageSize: 10,
            name: null,
            hospitalid: null
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
          },
            total: 25689,
            keyword:'',
            editDialogVisible: false,
            editData: null,
            tableData: [
                {
                    order: '01',
                    name: '李雷',
                    type: '临床',
                    qualification: '主治医生',
                    practiceScope: '儿科专业',
                    organization: '医科大医院',
                    region: '板桥镇',
                    prescriptionRight: '1种',
                },
                {
                    order: '01',
                    name: '李雷',
                    type: '临床',
                    qualification: '主治医生',
                    practiceScope: '儿科专业',
                    organization: '医科大医院',
                    region: '板桥镇',
                    prescriptionRight: '1种',
                }
            ]
        }
    },
    watch: {
        total: {
            immediate: true,
            handler(val){
                this.setTotal(val)
            }
        }
    },
  created() {
    this.getList();
  },
    methods: {
      getList() {
        this.loading = true;
        listNurse(this.queryParams).then(response => {
          this.tableData = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.uniqueCode)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      submitForm() {
            if (this.editData.id != null) {
              updateNurse(this.editData).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.editDialogVisible = false;
                this.getList();
              });
            }
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除？').then(function() {
          return delNurse(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
        handleEdit(scope) {
        console.log(scope.row)
            this.editData = scope.row
            this.editData.id = scope.row.id
            this.editDialogVisible = true
        },
        handleClose() {
            this.editDialogVisible = false
            this.editData = null
        },
        setTotal(value){
            const resolveRoute = (this.$router.resolve({
                path: this.$route.path,
                query: {...this.$route.query, total: value}
            }))
            if(location.href.includes(resolveRoute.href)) return
            this.$router.replace({
                path: this.$route.path,
                query: {...this.$route.query, total: value}
            })
        },
        handleView(scope) {
          this.$router.push({ name: 'nurseDetail', params: { number: scope.row.id}});
        }
    },
}
</script>
<style scoped lang="scss">
.physician-list {
    height: 100%;
    display: flex;
    flex-direction: column;
}
.title {
    font-size: 26px;
    color: #4B4B4B;
    font-weight: bold;
    margin: 18px 0 24px;

    span {
        font-weight: 500;
        font-size: 18px;
        color: #4B4B4B;
        margin-left: 16px;
    }
}
.search-input {
    width: 264px;
    height: 47px;
    background: #FFFFFF;
    border-radius: 5px;

    ::v-deep input {
        line-height: 45px;
        height: 47px;
        display: inline-block;
    }

    ::v-deep .el-input__icon {
        line-height: 45px;
        height: 45px;
        vertical-align: -0.15em;
        color: #4373F1;
    }
}

.table {
    flex: 1;
    background-color: #fff;
    margin: 13px 0 16px;

    ::v-deep .table-header-cell {
        background-color: #EBEFF8;
        padding-left: 21px;
        font-weight: 500;
        font-size: 16px;
        color: #414141;
    }
    .el-table {
        height: 100%;
    }
    ::v-deep .el-table__cell {
        padding-left: 21px;
        font-weight: 500;
        font-size: 16px;
        color: #414141;
    }
    :v-deep .el-table__body-wrapper {
        height: 100%;
    }
    :v-deep .el-table__empty-block {
        height: 100%;
    }
    .operation {
        display: flex;
        align-items: center;
        height: 100%;

        .view, .edit, .delete {
            cursor: pointer;
            font-weight: 500;
            font-size: 16px;
            color: #414141;
            height: 16px;
            line-height: 16px;
            padding-left: 20px;
            background-repeat: no-repeat;
            background-position: 0 center;
            margin-right: 20px;
            user-select: none;
        }

        .view {
            background-image: url('~@/assets/images/table/view.png');
        }
        .edit {
            background-image: url('~@/assets/images/table/edit.png');
        }
        .delete {
            background-image: url('~@/assets/images/table/delete.png');
            margin-right: 0;
        }
    }
}

.edit-box {
    display: flex;
    flex-direction: column;
    align-items: center;

    ::v-deep .el-dialog__footer {
        display: none;
    }

    .submit {
        width: 164px;
        height: 56px;
        background: #4373F1;
        border-radius: 5px;
        user-select: none;
        line-height: 56px;
        color: #fff;
        text-align: center;
        margin-top: 22px;
        cursor: pointer;
    }
    .name {
        margin-bottom: 13px;
    }

    .name, .id-number, .antibiosisAuthority {
        display: flex;
        align-items: center;
        white-space: nowrap;
        width: 410px;
        height: 56px;
        line-height: 16px;
        background: rgba(238,238,238,0.38);
        border-radius: 5px;
        border: 1px solid #E5E5E5;
        font-weight: bold;
        font-size: 16px;
        color: #505050;
        padding: 20px 22px;

        ::v-deep input {
            border: none;
            background: rgba(238,238,238,0.38);
        }
    }
}
::v-deep .el-dialog:not(.is-fullscreen) {
    margin-top: 40vh !important;
}
</style>
